<template>
  <div class="edit">
    <h1
      style="
        font-weight: 700;
        font-style: normal;
        font-size: 24px;
        color: #344563;
        margin-bottom: 30px;
      "
    >
      编辑信息
    </h1>
    <div class="edit-box">
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formLabelAlign"
        >
          <el-form-item label="退料日期">
            <el-input v-model="formLabelAlign.returnDate" disabled></el-input>
          </el-form-item>
          <el-form-item label="退料单号">
            <el-input v-model="formLabelAlign.returnNo" disabled></el-input>
          </el-form-item>
          <el-form-item label="退料部门">
            <el-input v-model="formLabelAlign.personalDept" disabled></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="form">
        <el-form
          :label-position="labelPosition"
          label-width="80px"
          :model="formLabelAlign"
        >
          <el-form-item label="制单人">
            <el-input v-model="formLabelAlign.preparedBy" disabled></el-input>
          </el-form-item>
          <el-form-item label="审核状态">
            <el-select
              v-model="formLabelAlign.auditStatus"
              placeholder="审核状态"
              style="width: 100%; padding: 0"
            >
              <el-option
                :key="v"
                v-for="v in select2"
                :label="
                  v == 1
                    ? '待审核'
                    : v == 2
                    ? '审核通过'
                    : v == 3
                    ? '拒绝审核'
                    : '--'
                "
                :value="v"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="审核人">
            <el-input v-model="formLabelAlign.reviewedBy" disabled></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div style="text-align: center">
      <el-button style="margin-right: 20px; width: 100px" @click="cancel"
        >取消</el-button
      >
      <el-button
        type="danger"
        style="background: #6554c0; border: none; width: 100px"
        @click="save"
        >保存</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      labelPosition: "left",
      formLabelAlign: {
        auditStatus: "",
        personalDept: "",
        preparedBy: "",
        returnDate: "",
        returnNo: "",
        reviewedBy: "",
      },
      //备份刷新页面防丢失数据
      formData1: [],
      select2: [1,2,3],
      //当前登录人id信息
      ID:''
    };
  },
  methods: {
    cancel: function () {
      this.$router.push("/home/Bmtl");
    },
    //获取数据
    //渲染修改界面
    getEdit: function (v) {
      this.formLabelAlign.auditStatus=v.auditStatus;
      this.formLabelAlign.personalDept = v.personalDept;
      this.formLabelAlign.preparedBy = v.preparedBy;
      this.formLabelAlign.returnDate = v.returnDate;
      this.formLabelAlign.returnNo = v.returnNo;
      this.formLabelAlign.reviewedBy = v.reviewedBy;
    },
    getData: function () {
      let Data = this.$store.state.xjqVuex.stock;
      // console.log(this.formData);
      if (Data == "") {
        this.getEdit(this.formData);
      } else {
        this.getEdit(Data);
      }
    },
    //渲染下拉
    getSelect: function () {
      this.$axios({
        url: "/personal/pdept",
      }).then(({ data }) => {
        this.select1 = data.data;
      });
      // this.$axios({
      //   url: "/wReceiptManagement/status",
      //   method: "post",
      // }).then(({ data }) => {
      //   this.select2.push(data.data[0].auditStatus);
      //   this.select2.push(data.data[1].auditStatus);
      //   this.select2.push(data.data[3].auditStatus);
      // });
    },
    //审核保存
    save: function () {
      this.$axios({
        url: "/WReturnManagement/update",
        method: "put",
        data: {
          //审核状态
          auditStatus: this.formLabelAlign.auditStatus,
          //退料单号
          returnNo: this.formLabelAlign.returnNo,
          //审核人Id
          reviewedById:this.ID,
        },
      }).then(({data})=>{
        // console.log(data);
          if (data.code == 0) {
          this.$message.success("审核成功！");
          setTimeout(() => {
            this.$router.push("/home/Bmtl");
          }, 1000);
        } else {
          this.$message.error(data.msg);
        }
      });
    },
  },
  mounted: function () {
    this.getData();
    this.getSelect();
  },
  created: function () {
    //创建后获取session备份数据
    this.ID=JSON.parse(sessionStorage.getItem('user'))[0].id
    // console.log(this.ID);
    this.formData = JSON.parse(sessionStorage.getItem("Material"));
  },
};
</script>
<style lang="less" scoped>
.edit {
  padding: 40px;
}
.edit-box {
  display: flex;
  margin-bottom: 30px;
}
.form {
  height: auto;
  flex: 1;
  margin-right: 150px;
}
</style>